package com.download.zhuaba.Controller;

import com.download.zhuaba.Service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class NewsController {
    @GetMapping("/News.html")
    public String news(Model model, HttpServletRequest request, HttpSession session){
        if(request.getSession().getAttribute("loginUser")!=null){
            String str = NewsService.getHtml();
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","1");
            String str1=str.replace("/weibo?q=","https://s.weibo.com/weibo?q=");
            str1 = str1.replace("target=\"_blank\"","onclick=\"history(this)\" target=\"_blank\"");
            model.addAttribute("htmlCode1",str1);
            return "News";
        }
        else{
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","0");
            return "login";
        }
    }
}
